import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;

import util.MyMath;


public class MyObject extends WorldObject{
	public double radius, x, y, vX, vY, vMag, vDir, aX, aY, aMag, aDir, mass;
	public Wall.WallEdge lastCollision;
	public Graphics2D paintObject(Graphics2D g2)
	{
		g2.draw(new Ellipse2D.Double(getPos()[0]- getRadius(), getPos()[1]- getRadius(), getRadius()*2, getRadius()*2));
		return g2;
	}
	public MyObject(double radius, double x, double y, double vX, double vY, double aX, double aY)
	{
		this.radius = radius;
		this.x = x;
		this.y = y;
		this.vX = vX;
		this.vY = vY;
		this.aX = aX;
		this.aY = aY;
		updateDirections();
	}
	public void setVel(double vX, double vY)
	{
		this.vX = vX;
		this.vY = vY;
		updateDirections();
	}
	public void setAcc(double aX, double aY)
	{
		this.aX = aX;
		this.aY = aY;
	}
	public double[] getPos()
	{
		double[] returnPos = {x, y};
		return returnPos;
	}
	public double[] getVel()
	{
		double[] returnVel = {vX, vY};
		return returnVel;
	}
	public double[] getAcc()
	{
		double[] returnAcc = {aX, aY};
		return returnAcc;
	}
	public double getRadius()
	{
		return radius;
	}
	
	private void updateDirections()
	{
		vMag = Math.pow((Math.pow(vX, 2) + Math.pow(vY, 2)), .5);
		vDir = Math.atan(vY / vX);
		aMag = Math.pow((Math.pow(aX, 2) + Math.pow(aY, 2)), .5);
		aDir = Math.atan(aY / aX);
	}
	public boolean checkSphereCollision(MyObject obj)
	{
		if(distanceTo(obj) < radius + obj.radius)
		{
			obj.lastCollision = null;
			lastCollision = null;
			return true;
		}
		return false;
	}
	public MyObject setMass(double mass)
	{
		this.mass = mass;
		return this;
	}
	public boolean equals(MyObject obj)
	{
		if(x == obj.x && y == obj.y)
			return true;
		return false;
	}
	public double distanceTo(MyObject obj)
	{
		double distance = Math.pow(Math.pow(x - obj.x, 2) + Math.pow(y - obj.y, 2), .5);
		return distance;
	}
	public double[] getVVector()
	{
		double mag = Math.pow(Math.pow(vX, 2) + Math.pow(vY, 2), .5);
		double angle = MyMath.aTan(vY, vX);
		double[] vector = {mag, angle};
		return vector;
	}
	public void setVFromVector(double[] vector)
	{
		vX = vector[0] * Math.cos(vector[1]);
		vY = vector[0] * Math.sin(vector[1]);
	}
}
